package com.core.ui.customtag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import com.core.managers.SessionManager;

public class PageTitleView
        extends TagSupport {

	private static final long serialVersionUID = 1L;



	public PageTitleView() {

	}



	private boolean isAuthenticated () {

		SessionManager sessionManager = SessionManager.sharedInstance();

		return sessionManager.isAuthenticated();

	}



	private String logoutLink () {

		if ( this.isAuthenticated() ) {
			return "profile";
		} else {
			return "<a class=\"href_logout\" href=\"Logout\">Logout</a>";
		}
	}



	public int doStartTag ()
	        throws JspException {

		// Boolean titleIsAuthorized =
		// true;//LoginManager.isAuthorizedUserForRequest(request);

		String logoutLink = this.logoutLink();

		StringBuilder sb = new StringBuilder();
		sb.append("<link type=\"text/css\" rel=\"stylesheet\" href=\"css/login.css\">");
		sb.append("<div id=\"header\">");
		sb.append("<div class=\"header_top\">");
		sb.append("<div class=\"header_home\">");
		sb.append("<img class=\"home_link_img\" src=\"img/tasktrackerLogos.png\"></img>");
		sb.append("</div>");
		sb.append("<div class=\"header_user\">");
		sb.append(logoutLink);
		sb.append("</div>");
		sb.append("</div>");
		sb.append("</div>");

		try {
			JspWriter writer = pageContext.getOut();
			writer.append(sb.toString());
		} catch ( IOException e ) {
			throw new JspException(e.getMessage());
		}

		return SKIP_BODY;
	}
}
